Tag: for循环

在C#中多次初始化'for'循环

我怎么能(如果有可能的话)在C# for循环中初始化多个不同types的variables? 例: for (MyClass i = 0, int j = 1; j<3; j++,i++)

继续For循环

我有以下代码 For x = LBound(arr) To UBound(arr) sname = arr(x) If instr(sname, "Configuration item") Then '**(here i want to go to next x in loop and not complete the code below)** '// other code to copy past and do various stuff Next x 所以我想我可以简单地有语句Then Next x ,但是这给了一个“不适用于声明声明”的错误。 那么,我可以把什么后, If instr(sname, "Configuration item") Then使其继续为X的下一个值?

检查对象的Javascript数组中是否存在对象值,如果不是,则将新对象添加到数组中

如果我有以下的对象数组: [ { id: 1, username: 'fred' }, { id: 2, username: 'bill' }, { id: 2, username: 'ted' } ] 有没有办法通过数组循环来检查一个特定的用户名值是否已经存在,如果它没有做任何事情,但如果它不添加一个新的对象与所述用户名(和新ID)的数组? 谢谢!

如何从双/嵌套循环中的主/外循环中断开?

如果我有一个循环循环,一旦语句满足,我想打破主循环,我该怎么做呢? 这是我的代码: for(int d = 0; d < amountOfNeighbors; d++){ for(int c = 0; c < myArray.size(); c++){ if(graph.isEdge(listOfNeighbors.get(d), c)){ if(keyFromValue(c).equals(goalWord)){ // once this is true I want to break main loop. System.out.println("We got to GOAL! It is "+ keyFromValue(c)); break; // this breaks second loop not main one. } } } }

使用拼接在for循环中删除arrays中的项目

我想实现一种jQuery实时search。 但在发送input到服务器之前,我想删除我的数组中有3个或更less字符的所有项目(因为在德语中,这些字通常可以忽略search)所以["this", "is", "a", "test"]变成["this", "test"] $(document).ready(function() { var timer, searchInput; $('#searchFAQ').keyup(function() { clearTimeout(timer); timer = setTimeout(function() { searchInput = $('#searchFAQ').val().match(/\w+/g); if(searchInput) { for (var elem in searchInput) { if (searchInput[elem].length < 4) { //remove those entries searchInput.splice(elem, 1); } } $('#output').text(searchInput); //ajax call here } }, 500); }); }); 现在我的问题是,并不是所有的项目在我的for循环被删除。 如果我例如typ“这是一个testing”“是”被删除,“一个”保持。 的jsfiddle 我认为问题是for循环,因为如果我用splice删除一个项目,数组的索引会改变,所以它会继续“错误”的索引。 也许有人可以帮我吗?

For-loop性能:将数组长度存储在variables中

考虑相同循环迭代的两个版本: for (var i = 0; i < nodes.length; i++) { … } 和 var len = nodes.length; for (var i = 0; i < len; i++) { … } 后者的版本是否比前者更快?

在date时间对象上循环会产生一个数字迭代器

为什么遍历Date或POSIXct对象会导致numeric ? 例如: test = as.Date("2009-01-01") print( class( test ) ) # [1] "Date" for ( day in test ) { print( class( day ) ) } # [1] "numeric" POSIXct发生同样的情况: test = as.POSIXct("2009-01-01") print( class( test ) ) # [1] "POSIXct" "POSIXt" for ( day in test ) { print( class( day ) ) […]

如何在列表理解python框架两个for循环

我有两个列表如下 tags = [u'man', u'you', u'are', u'awesome'] entries = [[u'man', u'thats'],[ u'right',u'awesome']] 我想从entries提取条目: result = [] for tag in tags: for entry in entries: if tag in entry: result.extend(entry) 我怎样才能把这两个循环写成单行列表的理解?

用C中的指针循环

我不明白指针在for循环中的作用。 *p在后面的循环中做了什么? char str[128] = "Some Text"; char *p; for (p = str; *p /*what does this mean?*/; p++) { // Code } 我明白了其余的,但为什么不是像p > 3或类似的东西? 为什么独自一人? 为什么这样写呢?

Javascript:在循环中隐藏原型方法?

所以可以说我已经添加了一些原型方法到Array类: Array.prototype.containsKey = function(obj) { for(var key in this) if (key == obj) return true; return false; } Array.prototype.containsValue = function(obj) { for(var key in this) if (this[key] == obj) return true; return false; } 然后我创build一个关联数组并尝试循环它的关键字: var arr = new Array(); arr['One'] = 1; arr['Two'] = 2; arr['Three'] = 3; for(var key in arr) alert(key); […]