Question: Given the following two C++ or Java like for loop, for (int j = 0; j < 10; j++) { //code 1 //codes omitted }

  1. Given the following two C++ or Java like for loop,

for (int j = 0; j < 10; j++) { //code 1

//codes omitted

}

//more codes here

int j; //code 2

for ( j= 0; j < 10; j++) {

//codes omitted

}

//more codes here

  1. What is the scope of j in each of above codes respectively?
  2. If Id display js value after (i.e. outside) the loop, will there be an error?
  3. Given a Python for loop and a Java/C++ loop below, could you guess what values will be printed out, respectively?

#Python loop

for j in range(10) : #range(10) will generate 0, 1, ,9

j=j+1

print(j)

//Java loop

for (int j=0; j<10; j++) {

j=j+1;

System.out.println(j);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!