Java/C2/For-Loop/English-timed

From Script | Spoken-Tutorial
Revision as of 12:20, 30 May 2013 by Sneha (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Time' Narration
00:02 Welcome to the spoken tutorial on for loop in java.
00:07 In this tutorial, you will learn how to use the for loop in Java.
00:12 For this tutorial we are using
  • Ubuntu 11.10,
  • JDK 1.6 and
  • Eclipse 3.7.0


00:24 For this tutorial, you should have knowledge on relational operators and if statement in Java.


00:32 If not, for relevant tutorial please visit our website which is as shown http://spoken-tutorial.org.
00:40 Here is the syntax of the for loop.
00:44 It consisits of initialization, loop condition and increment.
00:51 Then it has the for block which keeps on executing till the loop condition is true.
01:00 Now, let us try out an example in Eclipse.
01:04 So switch to eclipse
01:07 We already have a class named ForLoopDemo.


01:12 Let us add the for loop inside the main method.
01:17 So Inside the main function, type int i semicolon.


01:24 Then for within parenthesis i equal to 0 semicolon i less than 10 semicolon i equal to i plus 1.


01:45 This statement decides how the loop is going to progress.
01:53 i =0 is the starting condition for the loop.


01:58 This condition allows the variable to be initialized.
02:05 i<10 is the loop running condition.


02:09 If the condition is true then the for block will be executed.


02:14 Else it will be ignored.


02:17 That means when i becomes more than or equal to 10, the block is not executed.
02:25 Then i= i+1 , states how the loop variable is going to change.


02:32 Here, the value of i starts with 0.


02:35 It keeps increasing by 1 for every iteration of the loop until it becomes 10.


02:42 Now let us do something with i.
02:46 So open and close curly brackets.


02:49 Inside the curly brackets type System dot out dot println and print i into i.


03:06 This will print the square of each number from 0 to 9.


03:11 Let us see the output.


03:13 So save and run the program
03:17 As we can see, the loop run over numbers from 0 to 9.


03:23 The square of the number has been printed in each iteration.


03:28 Now let us print all the 2 digit numbers that are multiples of 3 or 5.
03:37 So, i should have values from 10 to 99.


03:42 So change i equal to 0 to i equal to 10.
03:48 And i less than 10 to i less than 100.
03:54 Then inside the curly brackets We print the number only if it is a multiple of 3 or 5.


04:03 So type,
04:04 if within brackets i mod 3 double equal to 0 or within brackets i mod 5 double equal to 0.


04:32 This statement checks whether i is divisible by 3 or by 5.


04:38 Then, in curly bracket we print the value of i
04:50 Now, let us see the output.
04:52 So save and run the program


04:56 We can see that the numbers are either multiples of 3 or 5. In this way we use for loop in Java
05:11 We have come to the end of this tutorial.
05:14 In this tutorial we have learnt how to use for loop in java.
05:20 For assignment , a three digit number is called Armstrong Number if it is equal to the sum of cubes of its digits.


05:29 For example, 153 is equal to 1 cube plus 5 cube plus 3 cube.


05:36 Find all such 3 digit numbers.
05:40 To know more about the Spoken Tutorial project,
05: 42 watch the video available at the spoken-tuitorial.org/what is a spoken-tuitorial?
05:49 it summarises the spoken tutorial project. If you do not have good bandwidth you can download and watch it.
05:56 The Spoken Tutorial Project Team. Conducts workshops using spoken tutorials
06:01 gives certificates for those who pass an online test.
06:04 For more details, please write to contact AT spoken HYPHEN tutorial DOT org.
06:10 Spoken Tutorial Project is a part of the Talk to a Teacher project and is supported by the National Mission on Education through ICT, MHRD, Government of India.
06:20 More information on this Mission is available at spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro
06:28 This script has been contributed by TalentSprint. This is Prathamesh Salunke signing off.

Thanks for joining.



Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14, Sneha