next 2 Mp3's on the list, can someone help me with this?
I want to display all the Mp3's that are left
You could use Console.ReadKey to wait for any input key, and use the same logic to print rest of the records.
int maxCount = 3;
for (int i = 0; i < maxCount && i < Mp3spelers.Count(); i++)
{
Console.WriteLine(Mp3spelers[i].ID);
Console.WriteLine(Mp3spelers[i].make);
Console.WriteLine(Mp3spelers[i].mbsize);
Console.WriteLine(Mp3spelers[i].model);
Console.WriteLine(Mp3spelers[i].price);
Console.WriteLine(Mp3spelers[i].voorraad);
}
Console.ReadKey(); // wait for key-in
// print remaining records.
for (int i = maxCount ; i < Mp3spelers.Count(); i++)
{
Console.WriteLine(Mp3spelers[i].ID);
Console.WriteLine(Mp3spelers[i].make);
Console.WriteLine(Mp3spelers[i].mbsize);
Console.WriteLine(Mp3spelers[i].model);
Console.WriteLine(Mp3spelers[i].price);
Console.WriteLine(Mp3spelers[i].voorraad);
}
You could use the Console.ReadKey and loop through the list again and start from the index where you left off initially.
for (int i = maxCount; i < Mp3spelers.Count(); i++)
{
Console.WriteLine(Mp3spelers[i].ID);
Console.WriteLine(Mp3spelers[i].make);
Console.WriteLine(Mp3spelers[i].mbsize);
Console.WriteLine(Mp3spelers[i].model);
Console.WriteLine(Mp3spelers[i].price);
Console.WriteLine(Mp3spelers[i].voorraad);
}
You could also make it a seperate method so you'll only have one place in your code to loop through your list and you can easily modify how many items you want to print and from what index to start printing.
public void ShowItemsInConsole(int firstIndex, int lastIndex)
{
for (int i = firstIndex; i < lastIndex && i < Mp3spelers.Count(); i++)
{
Console.WriteLine(Mp3spelers[i].ID);
Console.WriteLine(Mp3spelers[i].make);
Console.WriteLine(Mp3spelers[i].mbsize);
Console.WriteLine(Mp3spelers[i].model);
Console.WriteLine(Mp3spelers[i].price);
Console.WriteLine(Mp3spelers[i].voorraad);
}
}
Related
I want to initialize a square of textures with sf::sprite elements.
To make the main()-function as clean as possible, I wrote a function in another file, it looks like this:
vector<vector<sf::Sprite>> init_board_graphics(int size) {
sf::Texture _t1;
sf::Texture _t2;
_t1.loadFromFile("images/whitefield.png");
_t2.loadFromFile("images/blackfield.png");
vector<vector<sf::Sprite>> board;
//init vector for insert row-values
vector<sf::Sprite> help_vector;
for (int i = 0; i < size; i++) {
help_vector.clear();
for (int j = 0; j < size; j++) {
sf::Sprite insert_element;
if ((i + j) % 2 == 0) {
insert_element = sf::Sprite(_t1);
}
else {
insert_element = sf::Sprite(_t2);
}
insert_element.setPosition(i * pixel_field, j * pixel_field);
help_vector.push_back(insert_element);
}
board.push_back(help_vector);
}
return board;
}
When I call the function in main(), everything is fine at first, the elements are at the correct positions and the textures are also of correct size.
When I try to debug the next steps, I can observe that the textures of the elements are getting changed in size, even though the next lines have absolutely nothing to do with my object. First, I thought the entries are getting changed because I allocate the entries in the <vector<vector<sf::sprite>> - object in a wrong way but I fixed this:
if (parameters::visual_output) {
//Draw field
for (int i = 0; i < size_board; i++) {
vector<sf::Sprite> help_vec = board[i];
for (int j = 0; j < size_board; j++) {
window.draw(help_vec[j]);
}
}
}
The textures are still getting changed for some reason. Why is this happening?
Array1:
[[P01, 153425], [P02, 3951990], [P03, 106658], [P04, 4563594], [P05, 60198], [P07, 326292], [P08, 1265], [P09, 108293], [P10, 183698], [P11, 5084]] this comes from BigQuery.
Array2:
[[P01], [P02], [P03], [P04], [P05], [P06], [P07], [P08], [P09], [P10], [P11]]
this array is fetched from google sheet column using sheet.getSheetValues(3,1,11,1);
Based on this i should update a column in google sheet based on the matching values between Array1 and Array2:
eg: [153425,3951990,106658,4563594,60198,326292,1265,108293,183698,5084]
if value does not match the corresponding value should remain empty.
Compare Array1[i][0] with Array2[j] inside for loop, if it is equal take the value of Array1[i][1]
for(var i=0; i<Array1.length; i++){
for(var j=0; j<Array2.length; j++){
if(Array1[i][0] == Array2[j]){
//do something
//if it can be equal to only one number, you can break it here
}
}
}
EDIT
Then you should compare Array2[i] with Array1[j][0]
for(var i=0; i<Array2.length; i++){
var isExist = false;
for(var j=0; j<Array1.length; j++){
if(Array2[i] == Array1[j][0]){
//do something
//if it can be equal to only one number, you can break it here
isExist = true;
}
}
if(!isExist){
//do something if it does not exist
}
}
I have 2 while loops, and in the second there is a break; (see the code below)
My question is: will the break cause a stop in the second loop or for the 2?
while select dirPartyRelationship
join dirPartyTable
where dirPartyTable.RecId == dirPartyRelationship.ChildParty
join dirPersonName
where dirPersonName.Person == dirPartyTable.RecId
{
while select checkDirRelationship
where checkDirRelationship.ChildParty == dirPartyRelationship.RecId
{
if (checkDirRelationship.RelationshipTypeId == _relationshipType)
{
break;
}
}...
The break will only break out of the current code block.
Create a job and use this sample code;
for(i=0; i<100; i++)
{
for(j=0; j<100; j++)
{
info(strfmt("inner loop count %1",j));
break;
}
info(strfmt("outer loop count %1",i));
}
You will see a quick example of j never getting over 0, but being printed 100 times.
Edit;
If you want to break out of the nested loop you could work around by declaring a boolean, maybe called breakAll, and setting breakAll to true before the break; line in the inner loop. In the outer loop check for breakAll like this;
for(i=0; i<100; i++)
{
for(j=0; j<100; j++)
{
info(strfmt("inner loop count %1",j));
if (somethingToCheck)
{
breakAll = true;
break;
}
}
info(strfmt("outer loop count %1",i));
if (breakAll)
{
break;
}
}
I want to save remotely (on a database) the state (visible columns, columns width and order) of a Flex3 DataGrid.
For width and visibility I can simply save them by accessing each column attribute.. ugly but possible..
But for the order? Do I have to create the dataGrid dynamically??
Any idea is appreciated
thanks
In my case I have saved the order by header name (I'm making an assumption that your DataGrid always has the same columns and header names).
for (var n:Number = 0; n< datagrid.columns.length; n++)
{
var thiscol:DataGridColumn = DataGridColumn(datagrid.columns[n]);
colArray.addItem(thiscol.headerText);
}
Then I can restore the column order by retrieving the ordered list of column headers, and swapping the position of columns in the datagrid as required.
for (var n:Number = 0; n < colArray.length; n++)
{
moveColumnTo(String(colArray.getItemAt(n)), n);
}
I have defined a function moveColumnTo() to perform the switch.
private function moveColumnTo(columnName:String, columnIndex:Number):void
{
// Find current column position
var i:Number = -1;
for (var n:Number = 0; n < datagrid.columns.length; n++)
{
if (DataGridColumn(datagrid.columns[n]).headerText == columnName)
{
i = n;
break;
}
}
if (i == -1 || i == columnIndex) return; // Don't shift column
this.mx_internal::shiftColumns(i, columnIndex); // Shift column to required position
}
Why can't you just save the order as you're looping through each column?
for(var i:int = 0; i < dataGrid.columns.size; i++)
{
var column:DataGridColumn = dataGrid.columns[i];
arr.push({column.visible, column.width, i});
}
I'm creating a JsonArray such as:
JsonArray jsonValues = new JsonArray();
for( int i = 0; i < values.Count; i++ )
{
var someSingleValue = values[i];
jsonValues.Add( string.Format( "Name: {0}", someSingleValue ) );
}
After that I'm shipping json values to my javascript in .aspx page via call:
HtmlPage.Window.Invoke("call", jsonValues);
The call works and it gets there, however I have no idea how to iterate over those values, i.e extract them.
I've tried: (in javascript)
for (var x in somevalues){ alert(somevalues); }
I also tried:
for(var i = 0; i < somevalues.length; i++) {
alert(somevalues[i]);
}
but it crashes.(in both cases)
any ideas?
Are you using the eval method to serialize the string to a JSON object?
function call(somevalues){
//somevalues is currently just a string.
var results = eval("(" + somevalues +")");
//results now should contain your array as a JSON object.
//and you should be able to iterate over it at this point.
for(var i = 0; i < results.length; i++){
alert(results[i]);
}
}
Assuming somevalues is truly an array, you do it like this:
for(var i = 0; i < somevalues.length; i++) {
// do something with somevalues[i]
}
What you did was tell JavaScript to iterate over the properties of the somevalues object, which is similar, but not the same, as the iteration using a regular for loop.
EDIT: I am willing to bet your variable, somevalues is a string. Just do alert(somevalues) and see what happens.