标签: switch-statement

Scala开关在成功匹配后继续匹配下一个案例

如何在scala switch语句中执行一个case block block后执行另一个case块.(在java中:没有中断的情况).

switch(step) {
    case 0: do something;
    case 1: do something more;
    case 2: etc...;
            break;
    default: do something else;
}
Run Code Online (Sandbox Code Playgroud)

感谢帮助!

java scala switch-statement

3
推荐指数
2
解决办法
2603
查看次数

在Where子句中添加Case语句

我需要case在一个where子句中添加一个语句.我希望它根据TermDate的值运行下面的任何一个语句.

Select * 
from myTable
where id = 12345
    AND TermDate CASE  
    WHEN NULL THEN
       AND getdate() BETWEEN StartDate AND DATEADD(dd, 30, StartDate)
    ELSE
    AND GETDATE < TermDate
    END
Run Code Online (Sandbox Code Playgroud)

sql select case switch-statement

3
推荐指数
1
解决办法
5万
查看次数

切换声明Android

我的switch语句有问题.当我尝试从列表中选择一个项目时,它会自动执行switch语句的最后一个案例.这是我的代码:

CustomAdapter.java

@Override
 public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    Holder holder=new Holder();
    View rowView;        
         rowView = inflater.inflate(R.layout.list_field, null);
         holder.tv2=(TextView) rowView.findViewById(R.id.textView2);
         holder.tv=(TextView) rowView.findViewById(R.id.titleView);
         holder.img=(ImageView) rowView.findViewById(R.id.imageView1);

     holder.tv2.setText(description[position]);
     holder.tv.setText(result[position]);
     holder.img.setImageResource(imageId[position]);

     rowView.setOnClickListener(new View.OnClickListener() {

         @Override
         public void onClick(View v) {

            Intent intent = new Intent(context, Lesson.class); 

            switch(position){                                                     
                case 0: intent.putExtra("Title", l1);                   
                case 1: intent.putExtra("Title", l2);                   
                case 2: intent.putExtra("Title", l3);                   
                case 3: intent.putExtra("Title", l4);                   
                case 4: intent.putExtra("Title", l5);                   
                case 5: intent.putExtra("Title", l6);                   
                case 6: intent.putExtra("Title", l7); …
Run Code Online (Sandbox Code Playgroud)

android switch-statement

3
推荐指数
1
解决办法
1万
查看次数

C++:使用wstring切换的替代方法

在C++中switch使用a 有什么替代方法wstring吗?在Java中没有问题 - switch接受String.

c++ switch-statement

3
推荐指数
1
解决办法
1357
查看次数

在开关情况下不接受最终常数

我想知道方法add()中的2个声明之间的区别,如下所示.

final int c;
c = 20;
Run Code Online (Sandbox Code Playgroud)

和

final int c = 20;
Run Code Online (Sandbox Code Playgroud)

我认为两者都是最终变量,我无法重新分配任何新值.以下是以不同方式处理上述声明的方法.

void add() {
        final int a = 30;
        final int b = 10;
        final int c;
        c = 20;

        switch (a) {
        case b + c:
            System.out.println("In case b+c");
            break;

        default:
            break;
        }

    }
Run Code Online (Sandbox Code Playgroud)

抱怨,上面的方法根本没有编译

常数表达式需要案例b + c

如果声明变量c并在一行中初始化,例如final int c = 30;.有用.

java final switch-statement java-7

3
推荐指数
1
解决办法
695
查看次数

Ruby Switch中的返回命令?

我想从我的Case语句返回一个值,我需要执行多行代码,因此"then"对我不起作用.使用Return退出Case语句所在的函数.是否有一个关键字可以帮助我的代码清楚地暗示我返回的内容而不仅仅是在最后一行放一个值?

complexity = case(scale)
  when "gtp"
     x = [various lines of code]
     x = [various lines of code]
     10
  when "preSi"
     x = [various lines of code]
     x = [various lines of code]
     30
  when "postSi"    
     x = [various lines of code]
     x = [various lines of code]
     40
  else
     error"Scale not recognized: #{scale.to_s}"
  end
Run Code Online (Sandbox Code Playgroud)

ruby return-value switch-statement

3
推荐指数
2
解决办法
146
查看次数

无法分配给'let'值'action'

我正在尝试在switch语句之外定义一个常量,以便我可以在switch语句执行完毕后使用它并在switch语句中分配它:

let action: SKAction!

switch (whatever) {
case 0:
    sprite.position = CGPointMake(0, self.scene.size.height * lengthDiceroll)
    action = SKAction.moveTo(CGPointMake(self.scene.size.width, self.scene.size.height * (1 - lengthDiceroll)), duration: 1) // error here
    // other actions
default:
    println("meh")       

// add the sprite to the scene
let sequence = SKAction.sequence([action, action2])
sprite.runAction(SKAction.repeatActionForever(sequence))
self.addChild(sprite)
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误Cannot assign to 'let' value 'action'.如何分配操作以便我可以在交换机外部使用它?

如果我尝试:

action! = SKAction.moveTo(CGPointMake(self.scene.size.width, self.scene.size.height * (1.0 - lengthDiceroll)), duration: 1)
Run Code Online (Sandbox Code Playgroud)

我收到了错误"Could not find an overload for '*' that accepts the supplied arguments".

constants switch-statement swift

3
推荐指数
1
解决办法
4720
查看次数

R语言:在数值上切换案例

我想用数值切换案例,但我找不到一种自然的方法来做到这一点.这是我试过的:

这会导致语法错误:

fun <- function(x) {
    switch(x,
           0.2=0.1,
           0.9=0.6)
}
Run Code Online (Sandbox Code Playgroud)

这个编译,但有更好的解决方案吗?

fun <- function(x) {
    y <- as.character(x)
    switch(y,
           "0.2"=0.1,
           "0.9"=0.6)
}
Run Code Online (Sandbox Code Playgroud)

r switch-statement

3
推荐指数
1
解决办法
4601
查看次数

如何评估此switch语句?

编译器如何解释此switch语句?我假设switch语句中的内容是(41),为什么它会转到案例2?

    int i = 4;
    int j = 2;

    switch(i++-j) {         //switch is evaluted to be (41)??
    case 3: i++; break;
    case 1: j++; break;
    case 2: j+=2; break;
    case 5: i+=2; break;
    default: i +=5; break;
    }

    System.out.println(i);  //Prints out 4
    System.out.println(j);  //Prints out 5
Run Code Online (Sandbox Code Playgroud)

java switch-statement

3
推荐指数
1
解决办法
103
查看次数

在C#'switch'语句中更改变量

对于学校作业,我应该创建一个类似ATM的菜单.

我的教授给了我们这段代码:

string choice = null;

do
{
    Console.Write("[O]pen Account [I]nquire [D]eposit [W]ithdraw [Q]uit: ");
    choice = Console.ReadLine();
    choice = choice.ToUpper();

    switch (choice)
    {
        case "O": // open an account
        case "I": // inquire
        case "D": // deposit
        case "W": // withdraw
        default: break;
    }
} while (choice != "Q");
Run Code Online (Sandbox Code Playgroud)

这是我做的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string choice = null;
            string CustomerName;

            Console.WriteLine("Welcome to …
Run Code Online (Sandbox Code Playgroud)

c# switch-statement visual-studio

3
推荐指数
1
解决办法
568
查看次数

标签 统计

switch-statement ×10

java ×3

android ×1

c# ×1

c++ ×1

case ×1

constants ×1

final ×1

java-7 ×1

r ×1

return-value ×1

ruby ×1

scala ×1

select ×1

sql ×1

swift ×1

visual-studio ×1