Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-09-18 HW

posted Sep 18, 2017, 6:24 AM by Samuel Konstantinovich

Goal: While Loops


in python:

x = 0
while boolean:
  body

x=0

while x < 10

   #??? some code here

   x = x + 1


in netlogo:

while [boolean]
  [ body ]
let x 0
while [ x < 10]
[  
   ;???some code here
   set x (x + 1)
]

in java:

while(boolean){
   body
}

int x = 0;

while (x < 10){

   //??? Some code here

   x = x + 1;

}


GENERIC CODE:

// evaluate the boolean when it is true, go to INSIDE_LOOP

// when it is false go to AFTER_LOOP     

while (boolean){   

   //INSIDE_LOOP

//whatever code inside

//go back to boolean, redo the check.

}

//AFTER_LOOP


return one character in a string:

String s = "whatever"

            01234567


Go Over:

substring

chartAt


int i = 0;

while (i < s.length()){  // "<=" would cause an exception. "length()" is a method

System.out.println(s.substring(i, i +1));

i = i + 1; //  OR i += 1; OR i++; (only adds one)

}


Lab + Homework:

codingbat -> warmup2 ->

stringTimes

frontTimes

countXX

doubleX

stringBits

stringSplosion


String-2

doubleChar

countHi



Comments