Dasar-Dasar Pemrograman 2: Java Conditions and Loops

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Control Flow Statements: Repetition/Looping
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Computer Programming Lab 8.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
Chapter 3 Control Statements F Selection Statements –Using if and if...else –Nested if Statements –Using switch Statements –Conditional Operator F Repetition.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Control Structures if else do while continue break switch case return for.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Lecture 4 Control Structures MIT – AITI What are Control Structures? Control structures are a way to alter the natural sequence of execution in.
Chapter 3 Control Statements F Selection Statements –Using if and if...else –Nested if Statements –Using switch Statements –Conditional Operator F Repetition.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
Repetition Statements while and do while loops
Intro to Java Day 3 / Loops 1. DAY 3 Java Language Specifications Conditional Loops while do for References: JavaNotes7 pdf bookJavaNotes7 pdf book.
J AVA P ROGRAMMING 2 C H 03: C ONTROL STATEMENTS if, for loop (review) switch, while, do while break, continue Fall Java Programming.
Condition & loop Android Club Agenda if/else Switch Loops.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems 4. Controlling Execution SPARCS JAVA Study.
The for loop.
1/30/2016IT 2751 Operators Arithmetic operators: + - / * % Relational operators: == > = != Logical operators: || && !
Statements and Control Flow The programs we have seen so far do exactly the same list of instructions every time What if we want to do different things.
Introduction to Computing Concepts Note Set 14. What if… You had to print “I love Java” to the screen 125 times. How? 125 lines of ▫ System.out.println(“I.
Loops and Logic. Making Decisions Conditional operator Switch Statement Variable scope Loops Assertions.
CSE 110 Midterm Review Hans and Carmine. If Statements If statements use decision logic In order to properly use if statements relational operators must.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Lecture 4b Repeating With Loops
Course Outcomes of Programming In C (PIC) (17212, C203):
The switch Statement, and Introduction to Looping
Compound Condition Break , Continue Switch Statements in Java
Unit-1 Introduction to Java
Control Structures.
Introduction to programming in java
Computation as an Expressive Medium
Building Java Programs
null, true, and false are also reserved.
TO COMPLETE THE FOLLOWING:
The most important decision statement
Why arrays are cool 4/25/2007.
Building Java Programs
Building Java Programs
Lab5 PROGRAMMING 1 Loop chapter4.
class PrintOnetoTen { public static void main(String args[]) {
Chapter 5 server Side Scripting Date: 01 October 2017.
Building Java Programs
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Building Java Programs
Building Java Programs
Perfect squares class identifySquareButLessClever {
Program Flow.
Building Java Programs
Building Java Programs
Building Java Programs
Print the following triangle, using nested loops
Building Java Programs
Chapter 2 Lecture 2-2: The for Loop reading: 2.3
Loops CGS3416 Spring 2019 Lecture 7.
Foundations of Programming 2: Abstract Classes and Interfaces
Dasar-Dasar Pemrograman 2: Recursion
Dasar-Dasar Pemrograman 2: Generics
Dasar-Dasar Pemrograman 2: Java Basics
Presentation transcript:

Dasar-Dasar Pemrograman 2: Java Conditions and Loops Fariz Darari (fariz@cs.ui.ac.id) Credit: https://www.pexels.com/photo/black-and-white-roller-coaster-106155/ Feel free to use, reuse, and share this work: the more we share, the more we have!

Relational operators

Java has three logical operators && that is used for and || that is used for or ! that is used for not

Examples

De Morgan's laws

Conditions

if and else

Quiz time: What's wrong?

Quiz time: What's wrong?

Chaining if and else

Nesting if and else

while loop

while loop

for loop public static void countdown(int n) { for(int i = n; i > 0; i--) { System.out.println(i); } System.out.println("Blastoff!");

for loop

do-while loop int i = 0; do { System.out.println("Hi!"); } while (i!=0); Try run this, check if Hi! is still printed out or not

take a break int i = 0; while(i < 6) { System.out.print(i); if(i == 3) break; i++; } 0123

switch to be a better person Check this out too: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html switch to be a better person String you = "good"; switch(you) { case "bad": you = "good"; break; case "good": you = "better"; default: you = "best"; } System.out.println(you);

Credits: Think Java book by Allen Downey and Chris Mayfield Picture: https://unsplash.com/photos/VyC0YSFRDTU Credits: Think Java book by Allen Downey and Chris Mayfield