if else及嵌套迴圈

來源:互聯網
上載者:User

package com.xml.test;

public class Testc {

 /**
  * if else/ if else if if區別
  *   if(){
  *    條件成立則執行
  *   }else(){
  *    if條件不成立則執行此
  *   }
  * ------------------------------------------------------------------------------
  *   if(){
  *    條件成立則執行 
  *   }else if(){
  *    如果if不成立則判斷else if成立則執行
  *   }else if(){
  *    上述else if不成立則繼續判斷執行先一個else if,else if條件成立則不繼續往下判斷執行
  *   }else{
  *    如果上述所有if或者else if 條件均不成立則最後執行else塊
  *   }
  */
 public static void main(String[] args) {
  int a=100;
  if(a>1000){
   System.out.println("太好了,我可以買奧迪Q7啦");
  }else if(a>500){
   System.out.println("oh,我可以買奧迪沃爾沃cx90");
  }else if(a>95){
   System.out.println("也不錯,道奇酷威我也很喜歡");
  }else if(a>90){
   System.out.println("捷達有新款哦");
  }else{
   System.out.println("先把房子落實了吧");
  }
  circleControler();
  System.out.println("i am back to main...........");
 }
 
 /**
  * break return continue區別fs
  * break 強制中斷迴圈,迴圈體內的break之後的判斷語句一律不判斷,直接跳出迴圈體外
  *       在一系列的嵌套迴圈中使用break,他將僅僅終止最裡層迴圈
  *      
  * continue 語句執行continue時迴圈將跳過次部分,直接回到迴圈的起始地進行判斷和運算(a<10;a++)
  *
  * return 執行return時則會跳過該方法內所有嵌套迴圈直接跳轉到調用該方法的地方,繼續往下執行。
  * */
 public static  void circleControler(){
  for(int i=0;i<2;i++){
   for(int a =0;a<10;a++){
    System.out.println("starts............."+a);
    if(a==5){
     return;
    }
   }
   System.out.println("跳出For小迴圈.............");
  }
  System.out.println("跳出For大迴圈.............");
 }

}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.