Julia Tutorial - 7. For While Loop

codebasics · Beginner ·🛠️ AI Tools & Apps ·10y ago

Key Takeaways

Using for and while loops in Julia for iteration

Full Transcript

hello and welcome to Cod Basics coding tutorial today's topic is four and while loop in Julia and here is the list of items we are covering in this video okay let's begin with the for Loop we are going to cover two use cases of the for Loop the first one is iterating through an array you can do that by saying for I in your array print Ln I'm just printing all the elements in this array and you have to end the for loop with and keyword then you execute it it will just ited through each of these indivual elements one by one and at each stage I will contain those elements and it will print it here you can do same thing with a string array and I have this beautiful string array consisting of yummy Indian dishes and at each stage I am printing each of those items I hit alter enter by mistake so let me type this in again remember you have to put and otherwise you will get this error when you execute it it shows me this output okay the Second Use case is iterating using a range so let's say I want to print number one to five you can do that by typing in range like this here your starting index is one your endex ending index is one they separated by a column and I will just print I at every stage when I do that I get this output okay let's talk about while loop now uh I will print the same output uh using a while loop now now in case of file Loop you need to initialize your variable in advance you can't do it in within uh loop like this okay and then comes my while condition is a while I less than equal to 5 because I want to print number from 1 to 5 print Len uh I and I have to increment I if you forget to increment this then you will end up in an infinite Loop so make sure you don't forget this excellent so it printed what I was expecting it to print all right let's cover continue statement continue statement is used when you want to skip the execution of your um main Loop body for when certain condition is met for example I want to print a square of all numbers between 1 to 5 except even numbers so I want to skip even numbers and for remaining numbers I want to print the square for that I can do something like this so I'm using our range iteration here and the first thing I'm going to do is check if the number is even and as you know you can use percentage operator here to find out the remainder after dividing it by two and if it is zero as we all know from our school mathematics class that this number is even if it can be divided by two and you have to end if loop with and and I'm going to now print the remaining numbers okay so what it will do is if the number is even it will continue so it will continue means it will not come here it will just continue from this point and it will uh go into next iteration okay let's execute this excellent so I got the square of 1 3 and 5 and I skipped 2 and four because they were even numbers okay uh let's quickly cover break statement now break statement is used when uh you want to terminate the execution of your Loop when certain condition is met for example you lost your key in a home now you have certain locations to find your keys for example garage living room chair closet Etc once you find your key at one location you don't go to remaining location searching for it because your objective is met okay so for that uh we'll just quickly write a program to demonstrate the same thing and I'll show you how to use break here so for example let's say my key location is chair and my my possible locations in my home are all these locations okay so I'll say if I is equal to key location I'm searching through my home looking for my key and if I find my key I'm going to say that he found at this this particular location okay uh and I will break okay so from here on I don't want to execute uh the remaining part otherwise I will say print Len so first of all you have to end this and I say PR Ln [Music] key not found at I meaning I search through it I didn't find the key here and you have to put one more end to end your full loop here so let's see what happens excellent so here I just forgot to add one space I'll execute it again here it searched through garage it didn't find the key that's why I say not found living on not found but ultimately it found found the key at chair so it found it and then it breaks so it doesn't go through this last piece which is close it okay that was a quick demonstration of uh four and while look thank you for watching

Original Description

Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses. Website: http://codebasicshub.com/ Facebook: https://www.facebook.com/codebasicshub Twitter: https://twitter.com/codebasicshub
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from codebasics · codebasics · 26 of 60

1 Python Tutorial - 1. Install python on windows
Python Tutorial - 1. Install python on windows
codebasics
2 Python Tutorial - 2. Variables
Python Tutorial - 2. Variables
codebasics
3 Python Tutorial - 3. Numbers
Python Tutorial - 3. Numbers
codebasics
4 Python Tutorial - 4. Strings
Python Tutorial - 4. Strings
codebasics
5 Python Tutorial - 5. Lists
Python Tutorial - 5. Lists
codebasics
6 Python Tutorial - 6. Install PyCharm on Windows
Python Tutorial - 6. Install PyCharm on Windows
codebasics
7 PyCharm Tutorial - 7. Debug python code using PyCharm
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
8 Python Tutorial -  8. If Statement
Python Tutorial - 8. If Statement
codebasics
9 Python Tutorial - 9. For loop
Python Tutorial - 9. For loop
codebasics
10 Python Tutorial -  10. Functions
Python Tutorial - 10. Functions
codebasics
11 Python Tutorial - 11. Dictionaries and Tuples
Python Tutorial - 11. Dictionaries and Tuples
codebasics
12 Python Tutorial - 12. Modules
Python Tutorial - 12. Modules
codebasics
13 Python Tutorial - 13. Reading/Writing Files
Python Tutorial - 13. Reading/Writing Files
codebasics
14 How to install Julia on Windows
How to install Julia on Windows
codebasics
15 Python Tutorial - 14. Working With JSON
Python Tutorial - 14. Working With JSON
codebasics
16 Julia Tutorial - 1. Variables
Julia Tutorial - 1. Variables
codebasics
17 Julia Tutorial - 2. Numbers
Julia Tutorial - 2. Numbers
codebasics
18 Python Tutorial - 15. if __name__ == "__main__"
Python Tutorial - 15. if __name__ == "__main__"
codebasics
19 Julia Tutorial - Why Should I Learn Julia Programming Language
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
20 Python Tutorial  - 16. Exception Handling
Python Tutorial - 16. Exception Handling
codebasics
21 Julia Tutorial - 3. Complex and Rational Numbers
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
22 Julia Tutorial - 4. Strings
Julia Tutorial - 4. Strings
codebasics
23 Python Tutorial -  17. Class and Objects
Python Tutorial - 17. Class and Objects
codebasics
24 Julia Tutorial - 5. Functions
Julia Tutorial - 5. Functions
codebasics
25 Julia Tutorial - 6. If Statement and Ternary Operator
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
Julia Tutorial - 7. For While Loop
codebasics
27 Python Tutorial  - 18. Inheritance
Python Tutorial - 18. Inheritance
codebasics
28 Julia Tutorial - 8. begin and (;) Compound Expressions
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
29 Python Tutorial - 12.1 - Install Python Module (using pip)
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
30 Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
31 Julia Tutorial - 10. Exception Handling
Julia Tutorial - 10. Exception Handling
codebasics
32 Python Tutorial  - 19. Multiple Inheritance
Python Tutorial - 19. Multiple Inheritance
codebasics
33 Python Tutorial - 20. Raise Exception And Finally
Python Tutorial - 20. Raise Exception And Finally
codebasics
34 Python Tutorial - 21. Iterators
Python Tutorial - 21. Iterators
codebasics
35 Python Tutorial - 22. Generators
Python Tutorial - 22. Generators
codebasics
36 Python Tutorial - 23. List Set Dict Comprehensions
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
37 Python Tutorial - 24. Sets and Frozen Sets
Python Tutorial - 24. Sets and Frozen Sets
codebasics
38 Python Tutorial - 25. Command line argument processing using argparse
Python Tutorial - 25. Command line argument processing using argparse
codebasics
39 Debugging Tips - What is bug and debugging?
Debugging Tips - What is bug and debugging?
codebasics
40 Debugging Tips - Conditional Breakpoint
Debugging Tips - Conditional Breakpoint
codebasics
41 Debugging Tips - Watches and Call Stack
Debugging Tips - Watches and Call Stack
codebasics
42 Python Tutorial - 26. Multithreading - Introduction
Python Tutorial - 26. Multithreading - Introduction
codebasics
43 Git Tutorial 3:  How To Install Git
Git Tutorial 3: How To Install Git
codebasics
44 Git Tutorial 1: What is git / What is version control system?
Git Tutorial 1: What is git / What is version control system?
codebasics
45 Git Tutorial 2 : What is Github? | github tutorial
Git Tutorial 2 : What is Github? | github tutorial
codebasics
46 Git Tutorial 4: Basic Commands: add, commit, push
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
47 Git Tutorial 5: Undoing/Reverting/Resetting code changes
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
48 Git Tutorial 6: Branches (Create, Merge, Delete a branch)
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
49 Git Github Tutorial 10: What is Pull Request?
Git Github Tutorial 10: What is Pull Request?
codebasics
50 Git Tutorial 7: What is HEAD?
Git Tutorial 7: What is HEAD?
codebasics
51 Git Tutorial 9: Diff and Merge using meld
Git Tutorial 9: Diff and Merge using meld
codebasics
52 Difference between Multiprocessing and Multithreading
Difference between Multiprocessing and Multithreading
codebasics
53 Python Tutorial - 27. Multiprocessing Introduction
Python Tutorial - 27. Multiprocessing Introduction
codebasics
54 Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
55 Git Tutorial 8 - .gitignore file
Git Tutorial 8 - .gitignore file
codebasics
56 Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
57 Python Tutorial - 30. Multiprocessing Lock
Python Tutorial - 30. Multiprocessing Lock
codebasics
58 Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
59 What is code?
What is code?
codebasics
60 Python unit testing - pytest introduction
Python unit testing - pytest introduction
codebasics

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →