Looping Control Structure In VB6.0:- Sapan Das - .OnlineGuruji

.OnlineGuruji

Provides E-Notes,Video Tutorials And Download Links For Students In hindi

*********************************************************

*********************************************************
********************************************************************************

Breaking

Ramchandicollege Saraipali

Technology Jobs

OnlineGuru Blog मे आपका स्वागत है ब्लॉग से संबन्धित जानकारी के लिए संपर्क करें मो ॰ नम ।-9826026747(सपन कुमार दास) अपने विषय से संबन्धित अपडेट प्राप्त करने के लिए ब्लॉग पे दिये गए Bell Icon को press करें कम्प्युटर,Science,English Grammer से संबन्धित विषय की अधिक जानकारी के लिए हमारे ब्लॉग अथवा यू ट्यूब चैनल को सब्क्राइब करे ..

Friday, May 29, 2020

Looping Control Structure In VB6.0:- Sapan Das





Download Here   -Created By :- Sapan Das

Looping Control Structure

कंट्रोल स्ट्रक्चर का दूसरा भाग होता है looping structure इसकी आवश्यकता वहाँ  होती  है जहा किसी स्टेटमेंट को बार बार दोहराना होता है यह प्रोग्राम के किसी एक भाग को निश्चित समय तक दोहराता है यह कार्य तब तक बार बार होता रहता है  जब तक की दिया गया कंडिशन सत्य न हो जाए कंडिशन के false होने पर loop अपने आप ही समाप्त हो जाता है  और हम loop से बहार आ जाते है | प्रत्येक looping statement मे मुख्यतः तीन भाग होते| loop का स्टार्ट पॉइंट ,लूप का एंड पॉइंट और लूप का क्रम(incre /decre)

Types of looping statements

For –Next loop-  वीबी मे for loop मे for-next keyword का उपयोग होता है यहा for के साथ काउंटर variable को initilization किया जाता है तथा कंडिशन भी दिया जाता है यहा step keyword उपयोग कर लूप का ऑर्डर निर्धारित किया जाता है

और कंडिशन true होने पर body of loop execute होता है

Syntax

For var_name=(initialization) To var_name=(end point ) step 2

Statement

Next var_name

Example :-

Dim I As Integer

For I = 0 To 10

List1.AddItem (I)

Next I

Output :-











Private Sub Command2_Click()

Dim a As Integer

 For a = 2 To 20 Step 3 / 2 5 8 11 14 17 20

List1.AddItem ("Ramchandi College Saraipali")

       Next

End Sub 

उपरोक्त उदाहरण मे ramchandi college saraipali को 7 बार लिस्ट बॉक्स प्रिंट करेगा

Prog:- Write a prog to calculate the factorial number

Private Sub Command4_Click()

Dim i, f, num As Integer

f = 1

num = InputBox("Enter any Number")

For i = 1 To num

f = f * i

Next

MsgBox (f)

End Sub
















2-While –wend- इस लूप मे while wend keyword का उपयोग होता है इसमे काउंटर variable को initilize किया जाता है फिर while के साथ कंडिशन लगाया जाता है अगर कंडिशन true है तो body of loop execute होगा नहीं तो स्टॉप हो जाएगा

Syntax

Initilization

While (condition)

Body Of Loop

Incre/Decre

Wend

Example:

Dim I,j as integer

I=inputbox(“Enter Any Number”)===5

J= inputbox(“Enter Any Number”)---15

 

While i<=j

List1.add(i)

I=i+1

wend

 

Do while –Loop:- इस लूप मे do while loop  keyword का उपयोग होता है इसमे काउंटर variable को initilize किया जाता है फिर do -while के साथ कंडिशन लगाया जाता है अगर कंडिशन true है तो body of loop execute होगा नहीं तो स्टॉप हो जाएगा

Initilization

Do while condition

Body of loop

Incre/decr

Loop

Example:-

Dim x As Integer

x = o

Do While x <= 10

List1.AddItem (x)

x = x + 1

Loop

Do until –loop :- इस लूप मे do until loop  keyword का उपयोग होता है इसमे काउंटर variable को initilize किया जाता है फिर do until के साथ कंडिशन लगाया जाता है अगर कंडिशन false है तो body of loop execute होगा नहीं तो स्टॉप हो जाएगा यह लूप बाकी लूप से उल्टा चलता है

 

Syntax:-

Initialize variable

Do until condition

Statement

Incre/dec

Loop

I = 1

        Do Until I >= 11

            List1.AddItem (I)

            I = I + 2

        Loop

आउटपुट:-1 3 5 7 9

I = 11

        Do Until I >= 11

            List1.AddItem (I)

            I = I + 2

        Loop

 

आउटपुट:-no output (condition is true in first time )

Do...Loop While Statement

दो-लूप वाइल मे पहले स्टेटमेंट execute होता है उसके बाद कंडिशन चेक होता है अर्थात प्रत्येक बार स्टेटमेंट execute होता है फिर कंडिशन चेक होता है इस लूप मे कंडिशन true हो या false हो कम से कम एक बार तो स्टेटमेंट स्टेटमेंट ब्लॉक execute होगा ही  

Syntax:-

Initialization

Do

Statement

Incre/Decre

Loop while (condition)

Example :-

Dim number As Long

number = 6

Do

MsgBox (number)

number = number + 1

Loop While number < 5

The programs executes the statements between Do and Loop While structure in any case. Then it determines whether the counter is less than 5. If so, the program again executes the statements between Do and Loop While else exits the Loop.

For Each Next Loop :-

इस लूप का उपयोग किसी array अथवा collection मे प्रत्येक element के लिए group of statement को execute करने के लिए किया जाता है

Repeats a group of statements for each element in an array or collection.

For Each Next statements repeat a block of statements for each object in a collection or each element in an array.

Syntax

For Each element In group 
statements ] 
[ Exit For ] 
statements ] 
Next [ element ]
 

The For...Each...Next statement syntax has these parts:

उपरोक्त syntax मे element एक variant टाइप variable होता है जिसमे हम किसी object टाइप variable को assign करते है elelment की सहायता से ही हम किसी array अथवा collection के variable ko iterate करते है Group के अंतर्गत ayyay या collection होते hai statement optional होता है जिससे एक या एक से अधिक बार statement execute होता है

Goto statement :-

GoTo एक  unstructured control flow statement है यह code को less readable और maintainable बनाता है इसका उपयोग  Structured control flow statements जैसे  IfForWhile, आदि के स्थान पर कर सकते है

Example : -

Dim number As Integer

number = 3

        Dim sampleString As String

         If number = 1 Then GoTo Line1 Else GoTo Line2

Line1:

        sampleString = "Number equals 1"

        GoTo LastLine

Line2:

 sampleString = "Number equals 2"

LastLine:

Label1.Caption = sampleString







No comments:

Post a Comment