From the course: Programming for Non-Programmers: Android & Kotlin
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using loops
From the course: Programming for Non-Programmers: Android & Kotlin
Using loops
- [Instructor] In our calculator app, we're going to use a for loop to connect all of the numeric buttons to the same method. So to practice doing that, let's use a for loop here. I'm working with an example from a previous movie for those of you who are following along without the exercise files. So you can grab that previous exercise where you worked with arrays and just start from there. So here I have my buttons array and all of the OnClickListeners set for each item in the array. So let's set these with a loop instead of setting them manually. So I'm going to comment out these three lines of code and then I'm going to create a for loop below that. So for, and then I'll just press Return to use the code hinting, which only gives us parentheses, but it can still save you a little bit of time. Inside of the parentheses, type i and then in and then space buttons.indices. Now, if you're wondering about i, i is not something you have to use. You can name this anything you want…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Conditional statements3m 20s
-
(Locked)
Using conditional statements5m 11s
-
(Locked)
Boolean values6m 24s
-
(Locked)
Arrays1m 45s
-
(Locked)
Using arrays3m 4s
-
(Locked)
Loops3m 42s
-
(Locked)
Using loops4m 25s
-
(Locked)
When statements2m 29s
-
(Locked)
Using when statements8m 6s
-
(Locked)
Practical examples of conditional statements2m 35s
-
(Locked)
Challenge: Build a mini calculator app2m 19s
-
(Locked)
Solution: Build a mini calculator app3m 3s
-
-
-
-