While लूप्स

इंटरमीडिएट Julia

Anthony Markham

Quantitative Developer

While लूप्स - सिंटैक्स

  • for लूप से कम सामान्य, पर कई मामलों में उपयोगी.
  • जब तक condition true हो, expression दोहराएँ.
  • अक्सर किसी शर्त पूरी होने तक एक क्रिया दोहराने के लिए.
while condition
    expression
end
इंटरमीडिएट Julia

While लूप्स - उदाहरण

  • किसी शर्त के true होने तक क्रियाएँ दोहराएँ
counter = 10
while counter != 0
    print(counter, " ")
    counter = counter - 1
end
10 9 8 7 6 5 4 3 2 1
इंटरमीडिएट Julia

While लूप्स - पहला इटरेशन

# First iteration
counter = 10
while counter != 0  # counter = 10 here, so this is true
    print(counter, " ")  # print counter, equal to 10
    counter = counter - 1  # decrease the value of counter by 1
end
10
इंटरमीडिएट Julia

While लूप्स - दूसरा इटरेशन

# Second iteration
counter = 10
while counter != 0  # counter now = 9 here, so this is true
    print(counter, " ")  # print counter, equal to 9
    counter = counter - 1  # decrease the value of counter by 1
end
10 9
इंटरमीडिएट Julia

While लूप्स - तीसरा इटरेशन

# Third iteration
counter = 10
while counter != 0  # counter now = 8 here, so this is true
    print(counter, " ")  # print counter, equal to 8
    counter = counter - 1  # decrease the value of counter by 1
end
10 9 8
इंटरमीडिएट Julia

While लूप्स - अनंत लूप

  • अगर हम counter वैरिएबल को घटाना भूल जाएँ तो क्या होगा?
# Second iteration
counter = 10
while counter != 0  # counter now = 9 here, so this is true
    print(counter, " ")  # print counter, equal to 9
end
10 10 10 10 10 10 10 10 10
इंटरमीडिएट Julia

While लूप्स - टर्मिनेशन

  • DataCamp एनवायरनमेंट में, अनंत लूप से सेशन डिस्कनेक्ट हो जाएगा
  • अपनी लोकल मशीन पर, Ctrl + C से Julia प्रोग्राम समाप्त करें
इंटरमीडिएट Julia

अभ्यास करते हैं!

इंटरमीडिएट Julia

Preparing Video For Download...