Week 5: Objective C Loops
https://unsplash.com/photos/mZnx9429i94

Week 5: Objective C Loops

Today I want to talk about loops in Objective C programming language. There are plenty of instances where we can use loops to perform a specific action in the program. For example, this could be iterating through list numbers or string values. So today, we will break it down and how it is used correctly in Objective C.

For Loop

The For Loop is much more secure than other Loops such as While Loop and Do/While loop. The For Loop will first read what condition is declared in parenthesis, and if the condition is true, it will execute the code block. Listed below is an example of For Loop.

for ( int c = 1; i < 10 ; i ++ ) {


NSLog(@” The value of the index is %i” i);

}        

While-Loop

The while loop is formatted as shown below. We first declare our variable “c” with an integer value of “1”. The while is next announced, and the less-than operator is used to determine whether “c < 10”. If our code is valid and “1 < 10,” then our number value “c” will increment by “1” and execute until “c < 10” is false.

int c = 1

while ( c < 10 ) {

NSLog(@”Our new value will be %i”, c);

c++;?

}        

Do / While Loop

Do / While Loop is much different as it reads the Loop differently as it would read with a regular while loop. For example, let’s refer to Do / While loop listed below. The Do / While loop will first execute the line of code inside the brackets at least once before reading the condition “(c < 10)” to determine whether the condition is true or false.

int c = 1

do {

NSLog(@” The value of a is %i”, c);

c++;

} while ( c < 10);        

Break Statement

Breaking out of a loop can be executed by using a Break statement. If a specific condition needs to allow the loop to break out of its condition, then the break statement can be used in the loop. An example of a break statement is listed below.

for ( int c = 1; i < 10 ; i ++ ) {

NSLog(@”The value of the index is %i”, i);

If (c == 5) {

break;

???? }
}        

Loop Disassembly

Like being Conceal Carry Weapon applicant or purchasing a firearm, we will start breaking down the essential assemblies and understanding what makes up the commonly used Loop.

Here are important parts we need to remember and practice!

Int c = 1;

//1)        

1) This creates the index value for our integer variable “c.”

while ( i < 10)

//2)        

2) Checks the condition whether or not it’s true or false; this will determine if the code block executes the loop or not.

c++;

//3)         

3) Allows our index to increment depending on the condition.

Conclusion

Today we covered Objective C loops in IOS development. This week's lesson is essential for us to understand since we will commonly encounter loops in programming. I would like us to concentrate this week on getting our loops down. I'll be updating our flashcards this week, so please use them if required for review. I'll update this week when they are updated for this week's lesson plan. I hope everyone has a great day and happy coding!

要查看或添加评论,请登录

Michael Balsa的更多文章

社区洞察

其他会员也浏览了