如果你首先将它们存储在一个数组中,你可以这样做: for(i = 0; i< n; i ++){ if(array [i]!= value) { / * array [i]与价值不同,做点什么* / } } 但我没有var数组中的iables,并想弄清楚一个漂亮的oneliner。 Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array[i] != value) { /* array[i] differs from value, do something*/ } } but I dont have the variables in an array, and would like to figure out a nice oneliner. N个漂亮的衬里: if(var1!= value){/ * do smth * /} if(var2!= value){/ * do smth * /} .. .. if(varN!= value){/ * do smth * /} P.KruminsN nice one liners:if (var1 != value) { /* do smth */ }if (var2 != value) { /* do smth */ }....if (varN != value) { /* do smth */ }P.Krumins Einar写道:Einar wrote: 我想知道是否有一个很好的比较麻烦的黑客比较大量的变量? 如果你先将它们存储在一个数组中,你可以这样做: for(i = 0;我< N; i ++){ if(array [i]!= value){ / * array [i]与value不同,做点什么* / } } 但我没有数组中的变量,并且想弄清楚一个不错的oneliner。 Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array[i] != value) { /* array[i] differs from value, do something*/ } } but I dont have the variables in an array, and would like to figure out a nice oneliner. 我不确定你正在寻找什么,但它可能是 如果是(a!=值|| b!=值|| .. 。|| z!= value){ / * a,b,...,z中至少有一个与 *值不同,做点什么* / / *所有a,b,...,z与价值不同,做 *某事* / } 或 if(a!= value){ / * a与价值不同,做点什么* / } if(b!= value){ / * b不同于价值,做点什么* / } ... if(z!= value){ / * z不同于价值,做点什么* / } 或者如上所述,除了第一个`if''之前用'else'' 或 int * ptr [] = {& a,& b,...,& z}; for(i = 0;我< N; ++ i){ if(* ptr [i]!= value){ / * a,b,...,z的i'th不同于 *值,做点什么* / } } 如果没有这就是你要做的事情,你会想要更清楚地解释你的意图。 - Er ********* @ sun.comI''m not sure what you''re looking for, but it mightbe one ofif (a != value || b != value || ... || z != value) {/* at least one of a,b,...,z differs from* value, do something */}orif (a != value && b != value && ... &&& z != value) {/* all of a,b,...,z differ from value, do* something */}orif (a != value) {/* a differs from value, do something */}if (b != value) {/* b differs from value, do something */}...if (z != value) {/* z differs from value, do something */}or as above but with `else'' before all but the first `if''orint *ptr[] = { &a, &b, ..., &z };for (i = 0; i < n; ++i) {if (*ptr[i] != value) {/* The i''th of a,b,...,z differs from* value, do something */}}If none of these is what you''re trying to do, you''llhave to explain your intent more clearly.-- Er*********@sun.com Einar写道:Einar wrote: 我想知道是否有一个不错的讨厌hack来比较大量的变量? 如果你先将它们存储在一个数组中,你可以这样做: for(i = 0; i< n; i ++){ if(array [i]!= value){ / * array [i]与value不同,做点什么* / } } 但是我没有数组中的变量,并且想弄清楚一个不错的oneliner。 Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array[i] != value) { /* array[i] differs from value, do something*/ } } but I dont have the variables in an array, and would like to figure out a nice oneliner. N个不错的单行: if(var1!= value){/ *做smth * /} if(var2!= value){/ * do smth * /} .... if( varN!= value){/ * do smth * /} P.KruminsN nice one liners:if (var1 != value) { /* do smth */ }if (var2 != value) { /* do smth */ }....if (varN != value) { /* do smth */ }P.Krumins 这篇关于比较大量的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 21:35