課程
/后端開發
/C#
/C#開發輕松入門
為什么要括起來啊
2016-07-16
源自:C#開發輕松入門 3-7
正在回答
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int x = 5;
? ? ? ? ? ? int y = 6;
? ? ? ? ? ? if (x >= y)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (x >= 5)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("5");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? if (y >= 6)
? ? ? ? ? ? ? ? ? ? Console.WriteLine("6");
? ? ? ? ? ??
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? Console.WriteLine("7");
? ? ? ? }
? ? }
}
? ? ? ? ? ? ??
或號可以然一樣的代碼得出不同的輸出
一條的語句是以分號結尾。如果不括。跟if 或者else后面的只有一條語句是屬于他們的。其他的就不是。
而且,else是與其最近的if匹配
if(){
//if()里面為真,執行if語句,,否則執行else里面的語句
//大括號是為了表明if里面有哪些語句
//if下面只有一條命令,就可以不用大括號
else{
舉報
本門課程是C#語言的入門教程,將帶你輕松入門.NET開發
2 回答if。。。else的括號使用問題
1 回答if~else
2 回答if else
2 回答if...else...問題
2 回答? : 用原來的if...else表達是怎樣的
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-06-21
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int x = 5;
? ? ? ? ? ? int y = 6;
? ? ? ? ? ? if (x >= y)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (x >= 5)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("5");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? if (y >= 6)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("6");
? ? ? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? Console.WriteLine("7");
? ? ? ? ? ??
? ? ? ? }
? ? }
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int x = 5;
? ? ? ? ? ? int y = 6;
? ? ? ? ? ? if (x >= y)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (x >= 5)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("5");
? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? if (y >= 6)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("6");
? ? ? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? Console.WriteLine("7");
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
或號可以然一樣的代碼得出不同的輸出
2016-11-28
一條的語句是以分號結尾。如果不括。跟if 或者else后面的只有一條語句是屬于他們的。其他的就不是。
而且,else是與其最近的if匹配
2016-07-16
if(){
//if()里面為真,執行if語句,,否則執行else里面的語句
//大括號是為了表明if里面有哪些語句
//if下面只有一條命令,就可以不用大括號
}
else{
}